home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\EASYINST < prev    next >
Text File  |  1994-10-16  |  11KB  |  552 lines

  1. #!/bin/sh
  2. #
  3. # this script is a front end to `configure' which also asks a few
  4. # other questions such as default server, help service, etc.
  5. # $Id: easyinst,v 2.9 1994/10/16 05:37:35 mrg Stab $
  6. #
  7. # $defserver
  8. # $sysinstall (exists and is nonempty if system install)
  9. # $prefix
  10. # $bindir
  11. # $libdir
  12. # $help_service
  13. #
  14. # Eventually, if $HOME/.irc.easyinst.status defines no previous $libdir,
  15. # and the environment variable $IRCLIB is set and non-nul,
  16. # $libdir will default to that.
  17. #
  18.  
  19. #
  20. # Check if this is run through sh...
  21. #
  22. export PATH || \
  23. (echo "This shell does not look like sh... buggy OS."; sh $0; kill $$)
  24.  
  25. #
  26. # List of HELP SERVICES
  27. #
  28. help_services="NULL IrcIIhelp help_US help_UK help_AU help_EU"
  29.  
  30. #
  31. # File to save configuration in...
  32. #
  33.  
  34. # I guess root doesn't want a /.irc.easyinst.status file created
  35. if test -w /; then
  36.   savefile=/tmp/irc.easyinst.status
  37. else
  38.   savefile=$HOME/.irc.easyinst.status
  39. fi
  40.  
  41. #
  42. # The famous "no default" string
  43. #
  44. nodef="no default"
  45.  
  46. #
  47. # Checking out how to suppress new lines...
  48. #
  49. if [ "`echo -n a`" = "a" ]; then
  50.   n='-n'
  51.   c=''
  52. else
  53.   n=''
  54.   c='\c'
  55. fi
  56.  
  57. #
  58. # Set up ~user expansion
  59. cat >.tildexp <<EOF
  60. #!/bin/sh
  61. case "\$1" in
  62. ~/*|~)
  63.   echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
  64.   ;;
  65. ~*)
  66.   if test -f /bin/csh; then
  67.     /bin/csh -f -c "glob \$1"
  68.     failed=$?
  69.     echo ""
  70.     exit \$failed
  71.   else
  72.     name=\`$expr x\$1 : '..\([^/]*\)'\`
  73.     dir=\`$sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}' </etc/passwd\`
  74.     if test ! -d "\$dir"; then
  75.       me=\`basename \$0\`
  76.       echo "\$me: can't locate home directory for: \$name" \>\&2
  77.       exit 1
  78.     fi
  79.     case "\$1" in
  80.     */*)
  81.       echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
  82.       ;;
  83.     *)
  84.       echo \$dir
  85.       ;;
  86.     esac
  87.   fi
  88.   ;;
  89. *)
  90.   echo \$1
  91.   ;;
  92. esac
  93. EOF
  94. chmod a+x .tildexp
  95.  
  96. #
  97. # Set up shell script to read input
  98. #
  99. myecho="case \"\$xxxm\" in
  100. '') echo $n \"\$rp $c\" >&4;;
  101. *)  case \"\$rp\" in
  102.   '') echo $n \"[\$xxxm] $c\";;
  103.   *)
  104.     if test \`echo \"\$rp [\$xxxm]  \" | wc -c\` -ge ${COLUMNS-80}; then
  105.       echo \"\$rp\" >&4
  106.       echo $n \"[\$xxxm] $c\" >&4
  107.     else
  108.       echo $n \"\$rp [\$xxxm] $c\" >&4
  109.     fi
  110.     ;;
  111.   esac;;
  112. esac"
  113. cat <<EOF > .myread
  114. xxxm=\$dflt
  115. $myecho
  116. ans='!'
  117. case "\$fastread" in
  118. yes) case "\$dflt" in
  119.   '') ;;
  120.   *) ans='';
  121.     case "\$silent-\$rp" in
  122.     true-) ;;
  123.     *) echo " " >&4;;
  124.     esac;;
  125.   esac;;
  126. *) case "\$silent" in
  127.   true) case "\$rp" in
  128.     '') ans='';;
  129.     esac;;
  130.   esac;;
  131. esac
  132. while expr "X\$ans" : "X!" >/dev/null; do
  133.   read answ
  134.   set x \$xxxm
  135.   shift
  136.   aok=''; eval "ans=\"\$answ\"" && aok=y
  137.   case  "\$answ" in
  138.   "\$ans")
  139.     case "\$ans" in
  140.     "!")
  141.       sh 1>&4
  142.       echo " "
  143.       $myecho
  144.       ;;
  145.     !*)
  146.       set x \`expr "X\$ans" : "X!\(.*\)\$"\`
  147.       shift
  148.       sh 1>&4 -c "\$*"
  149.       echo " "
  150.       $myecho
  151.       ;;
  152.     esac;;
  153.   *)
  154.     case "\$aok" in
  155.     y)
  156.       echo "*** Substitution done -- please confirm."
  157.       xxxm="\$ans"
  158.       ans=\`echo $n "\$ans$c" | tr '\012' ' '\`
  159.       xxxm="\$ans"
  160.       ans=!
  161.       ;;
  162.     *)
  163.       echo "*** Error -- try again."
  164.       ans=!
  165.       ;;
  166.     esac
  167.     $myecho
  168.     ;;
  169.   esac
  170.   case "\$ans\$xxxm\$nostick" in
  171.   '')
  172.     ans=!
  173.     $myecho
  174.     ;;
  175.   esac
  176. done
  177. case "\$ans" in
  178. '') ans="\$xxxm";;
  179. esac
  180. EOF
  181.  
  182. trapdeletefiles=".myread .tildexp"
  183.  
  184. trap '{
  185.   exitstat=$?
  186.   rm -f $trapdeletefiles
  187.   trap "" 0
  188.   echo "Aborting... cleaning up." >&2
  189.   exit $exitstat
  190. }' 0 1 2 15
  191.  
  192. # Prepare redirection for "silent" mode (to be implemented :)
  193. exec 4>&1
  194.  
  195. cat << EOF
  196.  
  197. Welcome to the easy install script.
  198.  
  199. I will ask you a few questions. Most of the time, a default value will
  200. be printed, and you'll just need to hit the 'Return' key to confirm.
  201. If you get stuck on a question, you may use a ! shell escape to start
  202. a subshell or execute a !command.
  203.  
  204. Some questions asking for file or directory names allow the use of the ~user
  205. construct to specify the login directory belonging to "user", even if you
  206. don't have a shell which knows about that. They'll be marked "(~user ok)".
  207.  
  208. The prompter used in this script allows you to use shell variables and
  209. backticks in your answers.  You may use \$1, \$2, etc...  to refer to the words
  210. in the default answer, as if the default line was a set of arguments given to a
  211. script shell.  This means you may also use \$@ to repeat the whole default line,
  212. so you do not have to re-type everything to add something to the default.
  213.  
  214. Everytime there is a substitution, you will have to confirm.  If there is an
  215. error (e.g. an unmatched backtick), the default answer will remain unchanged
  216. and you will be prompted again.
  217.  
  218. If you are satisfied with your choices, I will then run a script for you
  219. to work out some of the hairier parts of your system. Good luck!
  220. EOF
  221. dflt="Press 'Return' to go on"
  222. . ./.myread
  223.  
  224. #
  225. # Trick to load old easyinst values :)
  226. #
  227. if test -r "$savefile"; then
  228.   echo "
  229. I see a $savefile file."
  230.   dflt="y"
  231.   rp="Do you want to use it to set the defaults?"
  232.   . ./.myread
  233.   case "$ans" in
  234.   n*|N*) echo "Ignoring $savefile." ;;
  235.   *)
  236.     echo "Loading previous easyinst choices..."
  237.     trap "{
  238.       rm -f $savefile
  239.       echo 'Fatal error. Please restart easyinst.' >&2
  240.     }" 0
  241.     . $savefile || \
  242.       (
  243.         echo 'Fatal error. Please restart easyinst.' >&2
  244.         rm -f $savefile
  245.         kill $$ \$\$
  246.       )
  247.     ;;
  248.   esac
  249.   trap 0
  250. fi
  251.  
  252. # Because the previous branch as squished the trap on exit
  253. trap '{
  254.   exitstat=$?
  255.   rm -f $trapdeletefiles
  256.   trap "" 0
  257.   echo "Aborting... cleaning up." >&2
  258.   exit $exitstat
  259. }' 0 1 2 15
  260.  
  261. # we have to get this from the user:
  262. #  default server, default help service, and where to install things.
  263.  
  264. # first we get the default server.
  265.  
  266. cat << EOF
  267.  
  268. I need to know the name of the irc server you intend to use as your
  269. primary link.  You should have done a little research by this time to see
  270. what servers are in your area. You should always pick the absolute closest
  271. server to you.  You can use an IP address instead of a name as well.
  272.  
  273. EOF
  274.  
  275. if test "$defserver"; then
  276.   dflt="$defserver"
  277. else
  278.   dflt="$nodef"
  279. fi
  280. rp="Please type the name of a server."
  281.  
  282. while true; do
  283.   . ./.myread
  284.   case "$ans" in
  285.   "$nodef")
  286.     continue
  287.     ;;
  288.   /*)
  289.     if test -f "$ans"; then :; else
  290.       echo "$ans doesn't seem to exist right now. You'll need to create it."
  291.     fi
  292.     ;;
  293.   *)
  294.     ;;
  295.   esac
  296.   break
  297. done
  298. defserver="$ans"
  299.  
  300. # got a default server, must be time to get the installation dir.
  301.  
  302. cat << EOF
  303.  
  304. Ok, we've got a default server now, next we have to choose where things
  305. are going to go.  First i need to know if you are compiling ircii for
  306. yourself, or for the system.
  307.  
  308. EOF
  309. if test "$prefix"; then
  310.   echo "Note: If you want to keep old directory values, just hit 'Return'.
  311. "
  312.   nostick=true
  313. fi
  314.  
  315. dflt=""
  316. rp="Do you want to install ircii for the system?"
  317. . ./.myread
  318. case "$ans" in
  319. y*|Y*)
  320.   sysinstall=nap
  321.   prefix="/usr/local"
  322.   bindir=
  323.   libdir=
  324.   ;;
  325. n*|N*)
  326.   sysinstall=
  327.   prefix="${HOME}"
  328.   bindir=
  329.   libdir=
  330.   ;;
  331. *)
  332.   prefix="${prefix-${HOME}}"
  333.   ;;
  334. esac
  335. nostick=""
  336.  
  337. cat << EOF
  338.  
  339. We now need to find out the destination area of the installation.
  340. Such a directory will probably have two subdirectories,
  341. something like 'bin' for the binaries, and 'lib/irc' for the libraries.
  342.  
  343. Hit 'Return' to keep previously computed values.
  344. EOF
  345. dflt="$prefix"
  346. rp='
  347. What is the destination prefix of the installation? (~user ok)'
  348. . ./.myread
  349. ans=`./.tildexp "$ans"`
  350.  
  351. #
  352. # If we have an answer, reset the other variables so that they get computed.
  353. #
  354. case "$ans" in
  355. "$dflt") ;;
  356. *)
  357.   prefix="$ans"
  358.   bindir=
  359.   libdir=
  360.   ;;
  361. esac
  362.  
  363. if test -z "$bindir"; then
  364.   bindir="${prefix}/bin"
  365. fi
  366.  
  367. dflt="$bindir"
  368. rp='
  369. Where do you want to install the ircII binaries? (~user ok)'
  370. . ./.myread
  371. ans=`./.tildexp "$ans"`
  372.  
  373. if test "$ans"; then bindir="$ans"; fi
  374.  
  375. #
  376. # Algorithm used:
  377. # Check if directory ${prefix}/lib exists...
  378. #   Yes -> install in ${prefix}/lib/irc
  379. #    No -> install in ${prefix}/IRC
  380. #
  381.  
  382. # If no $libdir is defined at this stage, but there's a $IRCLIB
  383. # in the environment, default to this value.
  384.  
  385. if test -z "$libdir"; then
  386.   if test "${IRCLIB}"; then
  387.     libdir="${IRCLIB}"
  388.   elif test -d "${prefix}/lib"; then
  389.     libdir="${prefix}/lib/irc"
  390.   else
  391.     libdir="${prefix}/IRC"
  392.   fi
  393. fi
  394.  
  395. dflt="$libdir"
  396. rp='
  397. Where do you want to install the irc librairies? (~user ok)'
  398. . ./.myread
  399. ans=`./.tildexp "$ans"`
  400.  
  401. if test "$answer"; then libdir="$answer"; fi
  402.  
  403. # ok, we have places to put things now.
  404.  
  405. cat << EOF
  406.  
  407. Moving right along here.  Time to tell me which help service you'd
  408. like to use.  Please enter the number of the one that is closest to you.
  409. You can choose 0) if you don't know.
  410.  
  411. EOF
  412.  
  413. index=0
  414. for a in $help_services; do
  415.   echo "    $index) $a"
  416.   index=`expr $index + 1`
  417. done
  418.  
  419. index=`expr "$index" - 1`
  420. echo ""
  421. while true; do
  422.   rp="Choice (0-$index)"
  423.   dflt="${help_service-$nodef}"
  424.   . ./.myread
  425.   case "$ans" in
  426.   "$nodef")
  427.     continue
  428.     ;;
  429.   *)
  430.     if test "$ans" -gt "$index" || test "$ans" -lt 0; then
  431.       :
  432.     else
  433.       break
  434.     fi
  435.   esac
  436. done
  437.  
  438. help_service="$ans"
  439. sedbit='[^ ]*'
  440. while test "$ans" -gt 0; do
  441.   ans=`expr $ans - 1`
  442.   sedfull="$sedbit $sedfull"
  443. done
  444.  
  445. if test -n "$sedfull"; then
  446.   defhelp=`echo $help_services | sed -e "s/$sedfull//" -e "s/ .*//"`
  447. else
  448.   defhelp=`echo $help_services | sed -e "s/ .*//"`
  449. fi
  450.  
  451. cat << EOF
  452.  
  453. I will summarize below the various choices you've made.
  454.  
  455.                 Default server: $defserver
  456.                         Prefix: $prefix
  457.     Directory for binary files: $bindir
  458.        Directory for libraries: $libdir
  459.                   Help service: $defhelp
  460.  
  461. EOF
  462.  
  463. rp='Do you want to save those values for future use and proceed?'
  464. dflt='y'
  465. . ./.myread
  466. case "$ans" in
  467. n*|N*)
  468.   echo "Exiting without saving..."
  469.   exit 1
  470.   ;;
  471. *)
  472.   ;;
  473. esac
  474.  
  475. {
  476.   cat << EOF
  477. #
  478. # ${savefile}
  479. # This file is automagically generated by the command 'easyinst'
  480. # Please do not edit.
  481. #
  482. EOF
  483.   echo '# $Id: easyinst,v 2.9 1994/10/16 05:37:35 mrg Stab $'
  484.   echo "# Created: `date`"
  485.   echo '# '
  486.   cat << EOF
  487. defserver="${defserver}"
  488. sysinstall="${sysinstall}"
  489. prefix="${prefix}"
  490. bindir="${bindir}"
  491. libdir="${libdir}"
  492. help_service="${help_service}"
  493.  
  494. EOF
  495. } > ${savefile}
  496.  
  497. cat << EOF
  498.  
  499. I just saved for you the current configuration in
  500.     $savefile
  501.  
  502. If you have made a typo, hit ^C now, edit this file and restart easyinst.
  503.  
  504. Now I will configure this version of ircii using the 'configure'
  505. script provided.
  506.  
  507. This may take a few minutes, so sit back an enjoy the show...
  508.  
  509. EOF
  510.  
  511. # work out what arguments to call configure with.
  512.  
  513. echo "setting up config.h..."
  514.  
  515. IRCLIB="$libdir"
  516.  
  517. if test "$defserver" || test "$defhelp"; then
  518.   rm -f include/config.h.old
  519.   mv include/config.h include/config.h.old
  520.   cp include/config.h.dist include/config.h
  521. fi
  522.  
  523. if test "$defserver"; then
  524.   sed -e "s@\(#define[     ]*DEFAULT_SERVER[     ]*\).*\$@\1 \"$defserver\"@" \
  525. < include/config.h > include/config.h.new
  526.   rm -f include/config.h
  527.   mv -f include/config.h.new include/config.h
  528. fi
  529.  
  530. if test "$defhelp"; then
  531.   if test "$defhelp" = "NULL"; then
  532.     defhelp="(char *) 0"
  533.   else
  534.     defhelp="\"$defhelp\""
  535.   fi
  536.   sed -e "s/\(#define[     ]*DEFAULT_HELP_SERVICE[     ]*\).*$/\1 $defhelp/" \
  537. < include/config.h > include/config.h.new
  538.   rm -f include/config.h
  539.   mv -f include/config.h.new include/config.h
  540. fi
  541.  
  542.  
  543. rm -f $trapdeletefiles
  544. trap 0 1 2 15
  545.  
  546. echo "calling configure..."
  547. . ./configure
  548.  
  549. # End of script
  550. exit 0
  551.  
  552.